package org.Gleipner;
 
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
 
public class MainMenuState extends BasicGameState {
 
    // Image Containers
    Image background;
    Image newGameImg;
    Image exitGameImg;

    // Menu Cordinations
    private static int menuX = 10;
    private static int menuY = 10;

    int stateID = 0;

    MainMenuState( int stateID ) 
    {
       this.stateID = stateID;
    }
 
    @Override
    public int getID() {
        return stateID;
    }
 
    @Override
    public void init(GameContainer gameContainer, StateBasedGame arg1) throws SlickException {
      // Load the Main Menu Images
      background = new Image("data/menu/background.jpg");
      newGameImg = new Image("data/menu/newgame.jpg");
      exitGameImg = new Image("data/menu/quitgame.jpg");
    }
 
    @Override
    public void render(GameContainer gameContainer, StateBasedGame arg1, Graphics arg2) throws SlickException {

      // Draw the background
      background.draw(0,0);

      // Draw the menu 
      newGameImg.draw(menuX, menuY);
      exitGameImg.draw(menuX, menuY+50);
 
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) throws SlickException {
        Input input = gc.getInput();
 
        int mouseX = input.getMouseX();
        int mouseY = input.getMouseY();
 
        boolean insideStartGame = false;
        boolean insideExit = false;
 
        if( ( mouseX >= menuX && mouseX <= menuX + newGameImg.getWidth()) &&
            ( mouseY >= menuY && mouseY <= menuY + newGameImg.getHeight()) )
        {
            insideStartGame = true;
        }else if( ( mouseX >= menuX && mouseX <= menuX+ exitGameImg.getWidth()) &&
            ( mouseY >= menuY+50 && mouseY <= menuY+50 + exitGameImg.getHeight()) )
        {
            insideExit = true;
        }
 
        if(insideStartGame)
        {
            if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
                sb.enterState(Gleipner.GAMEPLAYSTATE);
            }
        }
 
        if(insideExit)
        {
          if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
            gc.exit();
          }
        }

    } 
    
 
}
